﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr.Runtime;

namespace PSLib.Parsing.Common.Search
{
    /// <summary>
    /// Compares current token position with ElementSpan position
    /// </summary>
    internal class ElementSpanComparer : IComparer<object>
    {
        public ElementSpanComparer(CommonTokenStream stream)
        {
            this.CommonTokenStream = stream;
        }

        public int Compare(object x, object y)
        {
            ElementSpan span = (ElementSpan)y;
            IToken token = (IToken)x;
            int result = span.Compare(token.GetSpan(this.CommonTokenStream));
            return result;
        }

        public CommonTokenStream CommonTokenStream { get; set; }
    }
}
